<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of rbfhess</title>
  <meta name="keywords" content="rbfhess">
  <meta name="description" content="RBFHESS Evaluate the Hessian matrix for RBF network.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../menu.html">Home</a> &gt;  <a href="#">ReBEL-0.2.7</a> &gt; <a href="#">netlab</a> &gt; rbfhess.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../menu.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="menu.html">Index for .\ReBEL-0.2.7\netlab&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>rbfhess
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>RBFHESS Evaluate the Hessian matrix for RBF network.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [h, hdata] = rbfhess(net, x, t, hdata) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">RBFHESS Evaluate the Hessian matrix for RBF network.

    Description
    H = RBFHESS(NET, X, T) takes an RBF network data structure NET, a
    matrix X of input values, and a matrix T of target values and returns
    the full Hessian matrix H corresponding to the second derivatives of
    the negative log posterior distribution, evaluated for the current
    weight and bias values as defined by NET.  Currently, the
    implementation only computes the Hessian for the output layer
    weights.

    [H, HDATA] = RBFHESS(NET, X, T) returns both the Hessian matrix H and
    the contribution HDATA arising from the data dependent term in the
    Hessian.

    H = RBFHESS(NET, X, T, HDATA) takes a network data structure NET, a
    matrix X of input values, and a matrix T of  target values, together
    with the contribution HDATA arising from the data dependent term in
    the Hessian, and returns the full Hessian matrix H corresponding to
    the second derivatives of the negative log posterior distribution.
    This version saves computation time if HDATA has already been
    evaluated for the current weight and bias values.

    See also
    <a href="mlphess.html" class="code" title="function [h, hdata] = mlphess(net, x, t, hdata)">MLPHESS</a>, <a href="hesschek.html" class="code" title="function h = hesschek(net, x, t)">HESSCHEK</a>, <a href="evidence.html" class="code" title="function [net, gamma, logev] = evidence(net, x, t, num)">EVIDENCE</a></pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="consist.html" class="code" title="function errstring = consist(model, type, inputs, outputs)">consist</a>	CONSIST Check that arguments are consistent.</li><li><a href="hbayes.html" class="code" title="function [h, hdata] = hbayes(net, hdata)">hbayes</a>	HBAYES	Evaluate Hessian of Bayesian error function for network.</li><li><a href="rbffwd.html" class="code" title="function [a, z, n2] = rbffwd(net, x)">rbffwd</a>	RBFFWD	Forward propagation through RBF network with linear outputs.</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="#_sub1" class="code">function hdata = datahess(net, z, t)</a></li><li><a href="#_sub2" class="code">function hdata = rearrange_hess(net, j, out_hess, hdata)</a></li></ul>
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [h, hdata] = rbfhess(net, x, t, hdata)</a>
0002 <span class="comment">%RBFHESS Evaluate the Hessian matrix for RBF network.</span>
0003 <span class="comment">%</span>
0004 <span class="comment">%    Description</span>
0005 <span class="comment">%    H = RBFHESS(NET, X, T) takes an RBF network data structure NET, a</span>
0006 <span class="comment">%    matrix X of input values, and a matrix T of target values and returns</span>
0007 <span class="comment">%    the full Hessian matrix H corresponding to the second derivatives of</span>
0008 <span class="comment">%    the negative log posterior distribution, evaluated for the current</span>
0009 <span class="comment">%    weight and bias values as defined by NET.  Currently, the</span>
0010 <span class="comment">%    implementation only computes the Hessian for the output layer</span>
0011 <span class="comment">%    weights.</span>
0012 <span class="comment">%</span>
0013 <span class="comment">%    [H, HDATA] = RBFHESS(NET, X, T) returns both the Hessian matrix H and</span>
0014 <span class="comment">%    the contribution HDATA arising from the data dependent term in the</span>
0015 <span class="comment">%    Hessian.</span>
0016 <span class="comment">%</span>
0017 <span class="comment">%    H = RBFHESS(NET, X, T, HDATA) takes a network data structure NET, a</span>
0018 <span class="comment">%    matrix X of input values, and a matrix T of  target values, together</span>
0019 <span class="comment">%    with the contribution HDATA arising from the data dependent term in</span>
0020 <span class="comment">%    the Hessian, and returns the full Hessian matrix H corresponding to</span>
0021 <span class="comment">%    the second derivatives of the negative log posterior distribution.</span>
0022 <span class="comment">%    This version saves computation time if HDATA has already been</span>
0023 <span class="comment">%    evaluated for the current weight and bias values.</span>
0024 <span class="comment">%</span>
0025 <span class="comment">%    See also</span>
0026 <span class="comment">%    MLPHESS, HESSCHEK, EVIDENCE</span>
0027 <span class="comment">%</span>
0028 
0029 <span class="comment">%    Copyright (c) Ian T Nabney (1996-2001)</span>
0030 
0031 <span class="comment">% Check arguments for consistency</span>
0032 errstring = <a href="consist.html" class="code" title="function errstring = consist(model, type, inputs, outputs)">consist</a>(net, <span class="string">'rbf'</span>, x, t);
0033 <span class="keyword">if</span> ~isempty(errstring);
0034   error(errstring);
0035 <span class="keyword">end</span>
0036 
0037 <span class="keyword">if</span> nargin == 3
0038   <span class="comment">% Data term in Hessian needs to be computed</span>
0039   [a, z] = <a href="rbffwd.html" class="code" title="function [a, z, n2] = rbffwd(net, x)">rbffwd</a>(net, x); 
0040   hdata = <a href="#_sub1" class="code" title="subfunction hdata = datahess(net, z, t)">datahess</a>(net, z, t);
0041 <span class="keyword">end</span>
0042 
0043 <span class="comment">% Add in effect of regularisation</span>
0044 [h, hdata] = <a href="hbayes.html" class="code" title="function [h, hdata] = hbayes(net, hdata)">hbayes</a>(net, hdata);
0045 
0046 <span class="comment">% Sub-function to compute data part of Hessian</span>
0047 <a name="_sub1" href="#_subfunctions" class="code">function hdata = datahess(net, z, t)</a>
0048 
0049 <span class="comment">% Only works for output layer Hessian currently</span>
0050 <span class="keyword">if</span> (isfield(net, <span class="string">'mask'</span>) &amp; ~any(net.mask(<span class="keyword">...</span>
0051       1:(net.nwts - net.nout*(net.nhidden+1)))))
0052   hdata = zeros(net.nwts);
0053   ndata = size(z, 1);
0054   out_hess = [z ones(ndata, 1)]'*[z ones(ndata, 1)];
0055   <span class="keyword">for</span> j = 1:net.nout
0056     hdata = <a href="#_sub2" class="code" title="subfunction hdata = rearrange_hess(net, j, out_hess, hdata)">rearrange_hess</a>(net, j, out_hess, hdata);
0057   <span class="keyword">end</span>
0058 <span class="keyword">else</span>
0059   error(<span class="string">'Output layer Hessian only.'</span>);
0060 <span class="keyword">end</span>
0061 <span class="keyword">return</span>
0062 
0063 <span class="comment">% Sub-function to rearrange Hessian matrix</span>
0064 <a name="_sub2" href="#_subfunctions" class="code">function hdata = rearrange_hess(net, j, out_hess, hdata)</a>
0065 
0066 <span class="comment">% Because all the biases come after all the input weights,</span>
0067 <span class="comment">% we have to rearrange the blocks that make up the network Hessian.</span>
0068 <span class="comment">% This function assumes that we are on the jth output and that all outputs</span>
0069 <span class="comment">% are independent.</span>
0070 
0071 <span class="comment">% Start of bias weights block</span>
0072 bb_start = net.nwts - net.nout + 1;
0073 <span class="comment">% Start of weight block for jth output</span>
0074 ob_start = net.nwts - net.nout*(net.nhidden+1) + (j-1)*net.nhidden<span class="keyword">...</span>
0075    + 1; 
0076 <span class="comment">% End of weight block for jth output</span>
0077 ob_end = ob_start + net.nhidden - 1; 
0078 <span class="comment">% Index of bias weight</span>
0079 b_index = bb_start+(j-1);   
0080 <span class="comment">% Put input weight block in right place</span>
0081 hdata(ob_start:ob_end, ob_start:ob_end) = out_hess(1:net.nhidden, <span class="keyword">...</span>
0082    1:net.nhidden);
0083 <span class="comment">% Put second derivative of bias weight in right place</span>
0084 hdata(b_index, b_index) = out_hess(net.nhidden+1, net.nhidden+1);
0085 <span class="comment">% Put cross terms (input weight v bias weight) in right place</span>
0086 hdata(b_index, ob_start:ob_end) = out_hess(net.nhidden+1, <span class="keyword">...</span>
0087    1:net.nhidden);
0088 hdata(ob_start:ob_end, b_index) = out_hess(1:net.nhidden, <span class="keyword">...</span>
0089    net.nhidden+1);
0090 
0091 <span class="keyword">return</span></pre></div>
<hr><address>Generated on Tue 26-Sep-2006 10:36:21 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>